# Makefile for CS181 Neural Networks.
# Do not modify unless you add more source files.
#
# Please note that we use the g++ compiler to take 
# advantage of some C++ features such as streams.
# Feel free to use any C++ features you wish.

SUBMIT   = /usr/local/bin/submit
SOURCES  = neural-net.cc neural-net-impl.cc neural-net_main.cc data-reader.cc
HEADERS  = neural-net.h data-reader.h
OBJECTS  = $(SOURCES:.cc=.o)
RESULT   = neural-net_main
TESTS    = data-reader_test neural-net_test

GTEST_DIR = gtest-1.4.0
CC = g++
CCFLAGS = -I$(GTEST_DIR) -I$(GTEST_DIR)/include -g -O -Wall -ansi
RM = rm -f

$(RESULT): $(OBJECTS)
	$(CC) -o $@ $(OBJECTS)

# START Unit Test Support
GTEST_HEADERS = $(GTEST_DIR)/include/gtest/*.h \
                $(GTEST_DIR)/include/gtest/internal/*.h
# Usually you shouldn't tweak such internal variables, indicated by a
# trailing _.
GTEST_SRCS_ = $(GTEST_DIR)/src/*.cc $(GTEST_DIR)/src/*.h $(GTEST_HEADERS)


# For simplicity and to avoid depending on Google Test's
# implementation details, the dependencies specified below are
# conservative and not optimized.  This is fine as Google Test
# compiles fast and for ordinary users its source rarely changes.
gtest-all.o : $(GTEST_SRCS_)
	$(CC) $(CCFLAGS) -c $(GTEST_DIR)/src/gtest-all.cc

gtest_main.o : $(GTEST_SRCS_)
	$(CC) $(CCFLAGS) -c $(GTEST_DIR)/src/gtest_main.cc

gtest.a : gtest-all.o
	$(AR) $(ARFLAGS) $@ $^

gtest_main.a : gtest-all.o gtest_main.o
	$(AR) $(ARFLAGS) $@ $^
# END Unit Test support

.SUFFIXES: .cc .o

tests: $(TESTS)

all: $(RESULT) $(TESTS)

.cc.o:
	$(CC) $(CCFLAGS) $(CPPFLAGS) -c $<

clean:
	$(RM) $(RESULT) $(TESTS) *.o *.core core *~

submit: $(RESULT)
	$(RM) $(RESULT) *.o *.core core *~
	$(SUBMIT) cs181 2 `pwd`

neural-net.o: neural-net.cc neural-net.h data-reader.h
neural-net-impl.o: neural-net-impl.cc neural-net.h
neural-net_main.o: neural-net_main.cc neural-net.h data-reader.h
neural-net_test.o: neural-net_test.cc neural-net.h data-reader.h $(GTEST_HEADERS)
data-reader_test.o: data-reader_test.cc data-reader.h $(GTEST_HEADERS)
data-reader_test: data-reader.o data-reader_test.o gtest_main.a
neural-net_test: neural-net.o neural-net-impl.o gtest_main.a
